Two Data Providers


MGMT 638
Jones Graduate School of Business
Rice University
Fall 2022

Kerry Back

Examples of price signals

  • Moving averages
  • Relative strength index
  • Short-term (1 week or 1 month) reversals
  • Medium-term momentum (past six months or past year minus most recent month)

Yahoo adjusted close

Yahoo’s adjusted close is split and dividend adjusted.

!pip install pandas-datareader

from pandas_datareader import DataReader as pdr
aapl = pdr('aapl', 'yahoo', start=2010)
aapl = aapl['Adj Close']
aapl.head()
Date
2022-01-03    181.259933
2022-01-04    178.959442
2022-01-05    174.199158
2022-01-06    171.291183
2022-01-07    171.460495
Name: Adj Close, dtype: float64

Returns from Yahoo’s adjusted close

ret = aapl.pct_change()        # 1-day
ret5 = aapl.pct_change(5)      # 5-day
ret20 = aapl.pct_change(20)    # 20-day

df = pd.concat((aapl, ret, ret5, ret20), axis=1)
df.columns=['close', 'ret', 'ret5', 'ret20']
df = df.dropna()
df.head()

fret = aapl.pct_change(-1) ## AAPL and its moving average

Crossing the moving average

  • A downward cross occurs when AAPL > MvAvg one day and < the next.
  • An upward cross occurs when AAPL < MvAvg one day and > the next.
  • Does it have predictive power?
    • Next day return?
    • Next week return?
down = (aapl.shift()>ma50.shift()) & (aapl<ma50)
up = (aapl.shift()<ma50.shift()) & (aapl>ma50)
other = (!down) & (!up)
mean following down is nan%
mean following up is 0.82%
other mean is 1.18%